package org.headquarter.gui;

import org.boxlayout.gui.BoxLayoutEngine;
import org.boxlayout.widget.base.AbstractWidget;
import org.headquarter.object.Document;
import org.headquarter.object.Node;
import org.headquarter.object.Place;

public class WidgetNode extends AbstractWidget {

    Node node;
    
    public Node getNode() {
        return node;
    }

    public WidgetNode(BoxLayoutEngine ble) {
	super(ble);	
    }
    
    public void set(Node node){
	this.node = node;
	updateVisual();
    }
    
    public void loadNode(Node node){
	this.node = node;
	updateVisual();
	for(Node childNode : node.getChilds()){
	    if(childNode instanceof Place){
		WidgetPlace wp = new WidgetPlace(ble);
		wp.set(childNode);
		childContainer.add(wp.getVisual());
		childContainer.setEnable(true);
	    }else if(childNode instanceof Document){
		WidgetDocument wp = new WidgetDocument(ble);
		wp.set(childNode);
		childContainer.add(wp.getVisual());
		childContainer.setEnable(true);
	    }
	}
    }
    
    void updateVisual(){
	visual.setText(node.toString());
    }

}
